<li id="more_accountWrap" class="" style="position: relative;">
 	<label>结算账户:</label>
 	<span class="ui-combo-wrap ui-combo-active" id="account" style="padding: 0px; width: 110px;">
 		<input type="text" class="input-txt" autocomplete="off" style="width: 84px;font-size: 12px;" value="空"
 		id="accountWrapVal"><i class="trigger" id="more_account"></i>
 	</span>
 	<div class="ui-droplist-wrap" id="more_account_droplist" 
 	style="position: absolute; top: 30px; z-index: 1000; width: 110px; display: none; left: 94px;">
 	<div class="droplist" style="position: relative; overflow: auto; min-height: 150px; height: 150px;">
 		<div class="list-item selected" value="0" title="(空)">(空)</div>
 		<div class="list-item" value="-1" title="多账户">多账户</div>
 		{volist name="account" id="vo"}
 		<div class="list-item" value="{$vo.id}" title="{$vo.sn} {$vo.name}">{$vo.sn} {$vo.name}</div>
 		{/volist}
 	</div>
 </div>
 <a id="accountInfo" class="ui-icon ui-icon-folder-open" style="display: none;"></a>
</li>

<!-- 存放账户ID -->
<input type="hidden" name="" id="account_id" value="0">
<input type="hidden" name="" id="account_total_price" value="0">
<script type="text/javascript">
	$(document).ready(function () {
        // 选择结算账户-弹窗
        $("#more_accountWrap").on("click", "#more_account", function (e) {
        	var top = $(this).offset().top;
        	var left = $(this).offset().left;
        	$("#more_account_droplist").slideToggle();
           // $("#account_wrap").css({ "top": (top + 22) + "px", "left": (left - 158) + "px" })
       })
        //选择结算账户-赋值
        $("#more_account_droplist .droplist").on("click", ".list-item", function (e) {

        	var account_title = $(this).attr("title");
        	var account_value = $(this).attr("value");
            //结算账户
            if (account_value == -1) {
            	accountInfoFun('/admin/basic/multiple_accounts.html', this);
            	$("#accountInfo").css({ "display": "inline-block" })
            }else{
               $("#accountWrapVal").val(account_title);
               $("#account_id").val(account_value);
            }
            $("#more_account_droplist").hide();
        });
    })
     //选择结算账户-选择框外点击则隐藏
     $(document).mouseup(function (e) {
     	if(e.target.id!="more_account"){
            var con = $("#more_account_droplist");   // 设置目标区域
            if (!con.is(e.target) && con.has(e.target).length === 0) {
            	$("#more_account_droplist").hide();
            }
        } 
    });



</script>

<script type="text/javascript">
	//顺序函数
	function shunxu(account_body,callback){
		//console.log("z1");
		account_body.find('#save_child_grid').click();
		setTimeout(function () { 
           callback(1);
        }, 1000); 
	}

  // 多账户结算
  function accountInfoFun(url, obj) {
  	var o = $(obj);
  	layer.open({
  		type: 2,
  		title: "多账户结算",
  		shadeClose: true,
  		shade: 0.3,
      	maxmin: true, //开启最大化最小化按钮
      	area: ['725px', '410px'],
      	fixed: false, //不固定
      	btn: ['确定', '取消'],
      	//btn: ['btn1','btn2'],
      	content: url,
      	btn1: function (index, layero) {
	         var account_body = layer.getChildFrame('body', index);
	         //刷新子页面
	         shunxu(account_body,function(){
	         	var account_data = account_body.find('#grid').jqGrid('getGridParam','data');
		         //console.log("z3");
		         var account_flag = 0;
	    		 var account_jine_flag = 0;
	    		 var account_flag1=0;
	    		 var account_total_price=0;
			     account_data.forEach(function (self, index) {
			      //console.log(self);
			      if (self['account_id'] != null ) {
			        account_flag = account_flag + 1;
			        if (self['jine'] == null) {
			          account_jine_flag = 1;
			        }else{
			           account_total_price=account_total_price+parseFloat(self['jine']);
			           account_flag1 = account_flag1 + 1;
			        }
			      }
			    });
		        if (account_flag == 0) {
			      layer.msg("请选择结算账户");
			      return false;
			    }

			    if (account_jine_flag == 1) {
			      layer.msg("请填写金额");
			      return false;
			    }

			    if (account_flag != account_flag1) {
			      layer.msg("存在结算账户和金额未填写");
			      return false;
			    }

			    // if (account_flag != account_flag1) {
			    //   layer.msg("存在结算账户和金额未填写");
			    //   return false;
			    // }


 				localStorage.setItem("more_account_data",JSON.stringify(account_data)); 

			    $("#accountWrapVal").val("多账户");
	            $("#account_id").val(-1);
	            $("#account_total_price").val(account_total_price);
	            layer.close(index);
	            return false;

	         })
	         
	
   		},
		btn2: function (index, layero) {
	    	layer.close(index);
	    	return false;
	    }
	})
  }
</script>